package com.sdyeda.readiot.iotinfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import com.sdyeda.readiot.config.Setting;

@Service
public class IotInfoDaoImpl implements IotInfoDao {

    @Autowired //是用在JavaBean中的注解，通过byType形式，用来给指定的字段或方法注入所需的外部资源。
    private JdbcTemplate jdbcTemplate; //jdbc连接工具类
	
	//@Value("${com.sdyeda.readiot.sql-getiotinfo}")
    private String sql = (String)Setting.Get(Setting.SQL_GETIOTINFO);//= "select id,username,password from user";
    
	
    @Override
	public List<IotInfo> findall() {
		
    	//JdbcTemplate jdbcTemplate =new JdbcTemplate();
    	try {
    		return jdbcTemplate.query(sql, new BeanPropertyRowMapper<IotInfo>(IotInfo.class));
    	}
    	catch(Exception e) {
    		return null;
    	}
		//return null;
	}
    
    @Override
    public int add(IotInfo iotinfo) {
    	
    	Object[] args = {iotinfo.getId()};
    	
    	String addsql = "";
    	try {
    	return jdbcTemplate.update(addsql,args);
    	}
    	catch(Exception e) {
    		return 0;
    	}
    }


}
